/*
 * Framemain.java
 *
 * Created on 29 octobre 2007, 14:51
 */

package javaapplication;

import javax.swing.*;
import java.awt.*;

public class Framemain extends JFrame {
    
    public static final int LARGEUR_VOLET_DROIT = 400;
    public static final int LARGEUR_LANGUETTE   = 20;
    
    public static final Color FOND_VOLET = new Color(255, 255, 204);
    
    public Framemain() {
        initComponents();
        setPlanche(XPlancheMenuPrincipalConducteur.getInstance());
    }
    
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
        javax.swing.JPanel jPanel11;
        javax.swing.JPanel jPanel5;
        javax.swing.JPanel jPanel6;
        javax.swing.JPanel jPanel7;
        javax.swing.JPanel jPanel8;
        javax.swing.JPanel jPanel9;
        javax.swing.JScrollPane jScrollPane1;
        javax.swing.JPanel languetteDroite;
        javax.swing.JPanel panneauDroit;

        planche = new javax.swing.JPanel();
        voletDroit = new javax.swing.JPanel();
        panneauDroit = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        conteneurPlanche = new javax.swing.JPanel();
        languetteDroite = new javax.swing.JPanel();
        jPanel6 = new javax.swing.JPanel();
        jPanel11 = new javax.swing.JPanel();
        jPanel5 = new javax.swing.JPanel();
        jPanel9 = new javax.swing.JPanel();
        jPanel8 = new javax.swing.JPanel();
        jPanel7 = new javax.swing.JPanel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        planche.setMinimumSize(new java.awt.Dimension(400, 200));
        planche.setPreferredSize(new java.awt.Dimension(100, 200));
        javax.swing.GroupLayout plancheLayout = new javax.swing.GroupLayout(planche);
        planche.setLayout(plancheLayout);
        plancheLayout.setHorizontalGroup(
            plancheLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 211, Short.MAX_VALUE)
        );
        plancheLayout.setVerticalGroup(
            plancheLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 554, Short.MAX_VALUE)
        );
        getContentPane().add(planche, java.awt.BorderLayout.CENTER);

        voletDroit.setLayout(new java.awt.BorderLayout());

        voletDroit.setPreferredSize(new Dimension(LARGEUR_VOLET_DROIT, 0));
        panneauDroit.setBackground(FOND_VOLET);
        jScrollPane1.setBorder(null);
        jScrollPane1.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        conteneurPlanche.setLayout(new java.awt.BorderLayout());

        conteneurPlanche.setRequestFocusEnabled(false);
        jScrollPane1.setViewportView(conteneurPlanche);

        javax.swing.GroupLayout panneauDroitLayout = new javax.swing.GroupLayout(panneauDroit);
        panneauDroit.setLayout(panneauDroitLayout);
        panneauDroitLayout.setHorizontalGroup(
            panneauDroitLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panneauDroitLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 360, Short.MAX_VALUE)
                .addContainerGap())
        );
        panneauDroitLayout.setVerticalGroup(
            panneauDroitLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panneauDroitLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 532, Short.MAX_VALUE)
                .addContainerGap())
        );
        voletDroit.add(panneauDroit, java.awt.BorderLayout.CENTER);

        languetteDroite.setLayout(new java.awt.BorderLayout());

        languetteDroite.setBackground(new java.awt.Color(255, 255, 255));
        languetteDroite.setPreferredSize(new Dimension(LARGEUR_LANGUETTE, 0));
        languetteDroite.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                languetteDroiteMouseClicked(evt);
            }
        });

        jPanel6.setBackground(new java.awt.Color(0, 153, 255));
        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 8, Short.MAX_VALUE)
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 554, Short.MAX_VALUE)
        );
        languetteDroite.add(jPanel6, java.awt.BorderLayout.CENTER);

        jPanel11.setPreferredSize(new java.awt.Dimension(12, 100));
        jPanel5.setLayout(new java.awt.BorderLayout());

        jPanel5.setBackground(new java.awt.Color(0, 153, 255));
        jPanel5.setPreferredSize(new java.awt.Dimension(150, 150));
        jPanel9.setBackground(new java.awt.Color(255, 255, 255));
        jPanel9.setPreferredSize(new java.awt.Dimension(2, 100));
        jPanel8.setBackground(new java.awt.Color(51, 153, 255));
        jPanel8.setPreferredSize(new java.awt.Dimension(60, 60));
        javax.swing.GroupLayout jPanel8Layout = new javax.swing.GroupLayout(jPanel8);
        jPanel8.setLayout(jPanel8Layout);
        jPanel8Layout.setHorizontalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 2, Short.MAX_VALUE)
        );
        jPanel8Layout.setVerticalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 139, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout jPanel9Layout = new javax.swing.GroupLayout(jPanel9);
        jPanel9.setLayout(jPanel9Layout);
        jPanel9Layout.setHorizontalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel8, javax.swing.GroupLayout.DEFAULT_SIZE, 2, Short.MAX_VALUE)
        );
        jPanel9Layout.setVerticalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel9Layout.createSequentialGroup()
                .addComponent(jPanel8, javax.swing.GroupLayout.DEFAULT_SIZE, 139, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel5.add(jPanel9, java.awt.BorderLayout.WEST);

        jPanel7.setBackground(new java.awt.Color(51, 153, 255));
        jPanel7.setPreferredSize(new java.awt.Dimension(50, 50));
        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 10, Short.MAX_VALUE)
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 150, Short.MAX_VALUE)
        );
        jPanel5.add(jPanel7, java.awt.BorderLayout.CENTER);

        javax.swing.GroupLayout jPanel11Layout = new javax.swing.GroupLayout(jPanel11);
        jPanel11.setLayout(jPanel11Layout);
        jPanel11Layout.setHorizontalGroup(
            jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        jPanel11Layout.setVerticalGroup(
            jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        languetteDroite.add(jPanel11, java.awt.BorderLayout.WEST);

        voletDroit.add(languetteDroite, java.awt.BorderLayout.WEST);

        getContentPane().add(voletDroit, java.awt.BorderLayout.EAST);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void languetteDroiteMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_languetteDroiteMouseClicked
        afficherVolet();
    }//GEN-LAST:event_languetteDroiteMouseClicked
    
    
    private boolean voletAffiche = true;
    
    public void afficherVolet () {
        if (voletAffiche) {
            voletDroit.setPreferredSize(new Dimension(LARGEUR_LANGUETTE, 0));
        } else {
            voletDroit.setPreferredSize(new Dimension(LARGEUR_VOLET_DROIT, 0));
        }
        voletAffiche = !voletAffiche;
        voletDroit.updateUI();
    }
    
    
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                getInstance().setVisible(true);
            }
        });
    }
    
    
    public void setPlanche (XPlanche p) {
        if (p != null) {
            conteneurPlanche.removeAll();
            if (voletDroit.getPreferredSize().width != p.largeurRequise()) {
                voletDroit.setPreferredSize(new Dimension(p.largeurRequise(), 0));
                conteneurPlanche.setLayout(new BorderLayout());
                conteneurPlanche.add(p, BorderLayout.CENTER);
                voletDroit.updateUI();
            } else {
                conteneurPlanche.setLayout(new BorderLayout());
                conteneurPlanche.add(p, BorderLayout.CENTER);
                conteneurPlanche.updateUI();
            }
        }
    }
    
    private static Framemain instance;
    
    public static Framemain getInstance () {
        if (instance == null) {
            return instance = new Framemain();
        } else {
            return instance;
        }
    }
   
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel conteneurPlanche;
    private javax.swing.JPanel planche;
    private javax.swing.JPanel voletDroit;
    // End of variables declaration//GEN-END:variables
    
}
